/* TableViewController.m:
 * You may freely copy, distribute, and reuse the code in this example.
 * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
 * fitness for any particular use.
 *
 * Written by: Mai Nguyen, NeXT Developer Support
 *
 *
 */
#import "TableViewController.h"
#import "BooleanFormatter.h"

#define INSTALL_MODEL NXLocalizedString("Please install OracleDemo.dbmodel into your ~/Library/Databases directory and restart.", NULL, "Notify user that OracleDemo.dbmodel must be installed in his local Databases directory.")

@implementation TableViewController
/*
* Miscellaneous initialization tasks: connect to database, initialize
* tableview, set up dbModule. 
*/ 
-appDidInit:sender
{
	id vector;
		
	/* Notify the user if the database can't be found */
	if (!(dbDatabase = [DBDatabase findDatabaseNamed:"OracleDemo" 
					connect:YES])) {
		NXRunAlertPanel(NULL,INSTALL_MODEL, "OK", NULL, NULL);
		return self;
	}
	[dbDatabase setDelegate:self];
	
		/* Override the display of the boolean column */
	vector = [dbTableView columnAt:2];
	newFormatter = [[BooleanFormatter alloc] init];
	[vector setFormatter:newFormatter];
	return self;
}

- free
{
	if (newFormatter)
		[newFormatter free];
	return[super free];
}

/* DBDatabase delegate methods to log SQL queries  - Useful for debugging */

- (BOOL)db:aDb willEvaluateString:(const char*)aString usingBinder:aBinder
{
	fprintf(stderr, "SQL query:%s\n", aString);
	return YES;
}


@end
